﻿using System;
using UnityEngine;

namespace FBSAssist
{
	// Token: 0x0200058B RID: 1419
	public class AudioAssist
	{
		// Token: 0x06002200 RID: 8704 RVA: 0x00134E28 File Offset: 0x00133028
		public virtual float RMS(ref float[] samples)
		{
			float num = 0f;
			for (int i = 0; i < samples.Length; i++)
			{
				num += samples[i] * samples[i];
			}
			num /= (float)samples.Length;
			return Mathf.Sqrt(num);
		}

		// Token: 0x06002201 RID: 8705 RVA: 0x00134E6C File Offset: 0x0013306C
		public virtual float GetAudioWaveValue(AudioSource audioSource, byte type = 0, float correct = 2f)
		{
			float result = 0f;
			if (!audioSource.clip)
			{
				return result;
			}
			if (audioSource.isPlaying)
			{
				float[] data = new float[1024];
				float max = 1f;
				int num = audioSource.clip.samples * audioSource.clip.channels - audioSource.timeSamples;
				if (num <= 1024)
				{
					return result;
				}
				audioSource.clip.GetData(data, audioSource.timeSamples);
				float num2 = this.RMS(ref data);
				float num3 = Mathf.Clamp(num2 * correct, 0f, max);
				if (num3 < this.beforeVolume)
				{
					result = num3 * 0.2f + this.beforeVolume * 0.8f;
				}
				else
				{
					result = (num3 + this.beforeVolume) * 0.5f;
				}
				this.beforeVolume = num3;
			}
			return result;
		}

		// Token: 0x04002A76 RID: 10870
		protected float beforeVolume;
	}
}
